<!DOCTYPE html>
<html lang="en" >
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="author" content="GoJun" />
	
	
	
	<title>常用 Git 相关命令清单 ｜ GoJun</title>
	
    
    
    <meta name="description" content="Git git config --global user.name &amp;quot;Your Name&amp;quot; (安装完 git 后，设置用户名与邮箱) git config --global user.email &amp;quot;Your email&amp;quot; (设置邮箱) ssh-keygen -t rsa -C &amp;quot;youremail@example.com&amp;quot; (创建 SSH key) ssh-agent -s (查看 ssh 是否启用) ssh -T git@github.com (验证) git init (初始化一个本地仓库) git add . (将所有文件加入到跟踪列表) git commit -m &amp;quot;write something title&amp;quot; (" />
    

    
    
    <meta name="keywords" content="Hugo, theme, zozo" />
    

	
    
    <link rel="shortcut icon" href="https://gojun.me/images/favicon.ico" />

    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.mecss/normalize.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.0/animate.min.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.me/css/zozo.css" />
	<link rel="stylesheet" type="text/css" media="screen" href="https://cdn.jsdelivr.net/npm/remixicon@2.5.0/fonts/remixicon.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://gojun.me/css/highlight.css" />

    
    
</head>

<body>
    <div class="main animate__animated animate__fadeInDown">
        <div class="nav_container animated fadeInDown">
    <div class="site_nav" id="site_nav">
        <ul>
            
            <li>
                <a href="/">Home</a>
            </li>
            
            <li>
                <a href="/posts/">Archive</a>
            </li>
            
            <li>
                <a href="/tags/">Tags</a>
            </li>
            
            <li>
                <a href="/projects/">Projects</a>
            </li>
            
        </ul>
    </div>
    <div class="menu_icon">
        <a id="menu_icon"><i class="ri-menu-line"></i></a>
    </div>
</div>
        <div class="header animated fadeInDown">
    <div class="site_title_container">
        <div class="site_title">
            <h1>
                <a href="https://gojun.me">
                    <span>GoJun</span>
                </a>
            </h1>
        </div>
        <div class="description">
            <p class="sub_title">为向往生活努力奋斗！</p>
            <div class="my_socials">
                
                
                <a href="https://github.com/freelander" title="github" target="_blank"><i class="ri-github-fill"></i></a>
                
                
                <a href="https://gojun.me/index.xml" type="application/rss+xml" title="rss" target="_blank"><i
                        class="ri-rss-fill"></i></a>
            </div>
        </div>
    </div>
</div>
        <div class="content">
            <div class="post_page">
                <div class="post animate__animated animate__fadeInDown">
                    <div class="post_title post_detail_title">
                        <h2><a href='/posts/git-command/'>常用 Git 相关命令清单</a></h2>
                        <span class="date">2017.01.01</span>
                    </div>
                    <div class="post_content markdown"><h3 id="git">Git</h3>
<ol>
<li>
<p><code>git config --global user.name &quot;Your Name&quot;</code> (安装完 git 后，设置用户名与邮箱)</p>
</li>
<li>
<p><code>git config --global user.email &quot;Your email&quot;</code> (设置邮箱)</p>
</li>
<li>
<p><code>ssh-keygen -t rsa -C &quot;youremail@example.com&quot;</code> (创建 SSH key)</p>
</li>
<li>
<p><code>ssh-agent -s</code> (查看 ssh 是否启用)</p>
</li>
<li>
<p><code>ssh -T git@github.com</code> (验证)</p>
</li>
<li>
<p><code>git init</code> (初始化一个本地仓库)</p>
</li>
<li>
<p><code>git add . </code>(将所有文件加入到跟踪列表)</p>
</li>
<li>
<p><code>git commit -m &quot;write something title&quot;</code> (提交到本地仓库)</p>
</li>
<li>
<p><code>git status</code> (查看 git 文件哪处发生改动)</p>
</li>
<li>
<p><code>git remote add origin git@github.com:github账户名/github创建的库.git</code> (将本地仓库关联到 github 上远程仓库)</p>
</li>
<li>
<p><code>git push -u origin master</code> (将本地仓库的所有内容推送到远程库上，下一次推送时直接 git push)</p>
</li>
<li>
<p><code>git clone URL</code> (克隆远程仓库)</p>
</li>
<li>
<p><code>git branch</code> (查看当前分支)</p>
</li>
<li>
<p><code>git checkout -- filename</code> (文件恢复到最新版本，但丢失最近一次提交后你修改的内容)</p>
</li>
<li>
<p><code>git checkout name</code> (切换分支，name 为分支名称)</p>
</li>
<li>
<p><code>git reset --hard commitNumber</code> (回滚到某个 commit 不保存之前改动过的内容文件)</p>
</li>
<li>
<p><code>git push --force</code> (上条命令回滚之后的变更强行推送至服务器)</p>
</li>
<li>
<p><code>git tag</code> (查看本地 tag 列表)</p>
</li>
<li>
<p><code>git tag -d tagName</code> (删除本地 tag)</p>
</li>
<li>
<p><code>git push origin --tags</code> (将本地 tag 提交到远程)</p>
</li>
</ol>
<h3 id="git-flow">Git-Flow</h3>
<ol>
<li>
<p><code>git flow init</code> (初始化)</p>
</li>
<li>
<p><code>git flow feature start MYFEATURE</code> (开始新 Feature)</p>
</li>
<li>
<p><code>git flow feature publish MYFEATURE</code> (Publish 一个 Feature (也就是 push 到远程))</p>
</li>
<li>
<p><code>git flow feature pull origin MYFEATURE</code> (获取 Publish 的 Feature)</p>
</li>
<li>
<p><code>git flow feature finish MYFEATURE</code> (完成一个 Feature)</p>
</li>
<li>
<p><code>git flow release start RELEASE [BASE]</code> (开始一个 Release)</p>
</li>
<li>
<p><code>git flow release publish RELEASE</code> (Publish 一个 Release)</p>
</li>
<li>
<p><code>git flow release finish RELEASE </code> (发布 Release)</p>
</li>
<li>
<p><code>git push --tags</code> (发布 Release 后进行，push 到远程)</p>
</li>
<li>
<p><code>git flow hotfix start VERSION [BASENAME]</code> (开始一个 Hotfix)</p>
</li>
<li>
<p><code>git flow hotfix finish VERSION</code> (发布一个 Hotfix)</p>
</li>
</ol>
<h3 id="git-submodule">Git-Submodule</h3>
<ol>
<li>
<p><code>git submodule add git@github.com:github账户名/github创建的库.git</code> (在已存在 git 仓库添加子仓库)</p>
</li>
<li>
<p><code>git submodule init</code> (初始化 Submodule)</p>
</li>
<li>
<p><code>git submodule update</code> (更新 Submodule)</p>
</li>
</ol>
<h3 id="vim">vim</h3>
<ol>
<li>
<p><code>vim filename</code> (打开编辑文件)</p>
</li>
<li>
<p>按一下 <code>i</code> 键 (进行编辑文件)</p>
</li>
<li>
<p>按一下 <code>Esc</code> 键 (退出 <code>i</code> (插入)命令进行其它命令使用)</p>
</li>
<li>
<p><code>:wq</code> (保存文件并退出)</p>
</li>
<li>
<p><code>:q!</code> (强制退出,不保存)</p>
</li>
<li>
<p><code>:w filename</code> (将文件以指定的文件名 filename 保存)</p>
</li>
</ol>
<h3 id="git-flow-规范理解与延伸">Git-Flow 规范理解与延伸</h3>
<p>

<div class="fancybox">
<a data-fancybox="demo" href="/images/2017/01/03-1.png">
<img src="/images/2017/01/03-1.png" alt=""  />
</a>
</div>

</p>
<h3 id="git-commit-规范">Git Commit 规范</h3>
<p>为了更加方便查找 git commit 的日志，因此有必要在 commit 的时候进行备注说明类型</p>
<p>参考阮老师的文章：<a href="http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html">地址</a></p>
<p>与团队成员约定在 commit 填写 message 的时候，在前面加多一个 type，具体的类型如下：</p>
<table>
<thead>
<tr>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>feat</td>
<td>新功能（Feature）</td>
</tr>
<tr>
<td>fix</td>
<td>修补 bug</td>
</tr>
<tr>
<td>style</td>
<td>界面样式变动（不影响原有业务代码逻辑）</td>
</tr>
<tr>
<td>build</td>
<td>Gradle 构建的变动，例如第三方库版本号变动</td>
</tr>
</tbody>
</table>
<blockquote>
<p>例子：feat: 完成登录注册功能</p>
</blockquote>
<h3 id="参考链接">参考链接</h3>
<ul>
<li><a href="http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html">常用 Git 命令清单</a></li>
<li><a href="https://www.zybuluo.com/Roy270490837/note/835720">git-flow流程规范</a></li>
<li><a href="https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%AD%90%E6%A8%A1%E5%9D%97">Git 工具 - 子模块</a></li>
<li><a href="http://blog.devtang.com/2013/05/08/git-submodule-issues/">Git submodule的坑</a></li>
</ul>
</div>
                    <div class="post_footer">
                        
                        <div class="meta">
                            <div class="info">
                                <span class="field tags">
                                    <i class="ri-stack-line"></i>
                                    
                                    <a href="https://gojun.me/tags/git/">Git</a>
                                    
                                </span>
                            </div>
                        </div>
                        
                    </div>
                </div>
                
                
                <div class="doc_comments"></div>
                
            </div>
        </div>
    </div>
    <a id="back_to_top" href="#" class="back_to_top"><i class="ri-arrow-up-s-line"></i></a>
    <footer class="footer">
    <div class="footer_slogan">
        <span></span>
    </div>
</footer>
    <script src="https://gojun.me/js/jquery-3.5.1.min.js"></script>
<link href="https://gojun.me/css/fancybox.min.css" rel="stylesheet">
<script src="https://gojun.me/js/fancybox.min.js"></script>
<script src="https://gojun.me/js/zozo.js"></script>


<script type="text/javascript" async
    src="https://cdn.bootcss.com/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
        MathJax.Hub.Config({
            tex2jax: {
                inlineMath: [['$', '$'], ['\\(', '\\)']],
                displayMath: [['$$', '$$'], ['\[\[', '\]\]']],
                processEscapes: true,
                processEnvironments: true,
                skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
                TeX: {
                    equationNumbers: { autoNumber: "AMS" },
                    extensions: ["AMSmath.js", "AMSsymbols.js"]
                }
            }
        });

        MathJax.Hub.Queue(function () {
            
            
            
            var all = MathJax.Hub.getAllJax(), i;
            for (i = 0; i < all.length; i += 1) {
                all[i].SourceElement().parentNode.className += ' has-jax';
            }
        });
    </script>

<style>
    code.has-jax {
        font: inherit;
        font-size: 100%;
        background: inherit;
        border: inherit;
        color: #515151;
    }
</style>



<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'UA-142037913-1', 'auto');
	
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>

</body>

</html>